<template>
  <div class="form">
    <el-dialog v-dialogDrag class="transferDialog tiny-mce-dialog" :close-on-press-escape = "true" :show-close = 'false' center :modal="false" title="结算详情" width="800px" :visible.sync="isShow" @close="cancel('ruleForm')" :close-on-click-modal="false">
      <vue-scroll >
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" size="mini" :label-width="formLabelWidth">
        <el-tabs v-model="activeName" style="padding: 0" type="border-card"  @tab-click="handleClick">
          <el-tab-pane label="结算明细" name="settle">
            <el-card class="box-card">
              <div slot="header">
                <span>煤炭信息</span>
              </div>
              <el-row :gutter="24">
                <el-col :span="12">
                  <el-form-item label="矿发吨位" :label-width="formLabelWidth" prop="mineSendNum">
                    <el-input v-model="ruleForm.mineSendNum" readonly>
                      <template slot="append">吨</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="实收吨位" :label-width="formLabelWidth" prop="realNum">
                    <el-input v-model="ruleForm.realNum" readonly >
                      <template slot="append">吨</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="差异吨位" :label-width="formLabelWidth" prop="diffNum">
                    <el-input v-model="ruleForm.diffNum" readonly>
                      <template slot="append">吨</template>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
            <el-card class="box-card">
              <div slot="header">
                <span>费用</span>
              </div>
              <el-row :gutter="24">
                <el-col :span="12">
                  <el-form-item label="运费" :label-width="formLabelWidth" prop="freight">
                    <el-input v-model="ruleForm.freight" readonly>
                      <template slot="append">元/吨</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="装车费" :label-width="formLabelWidth" prop="loadFee">
                    <el-input v-model="ruleForm.loadFee" readonly>
                      <template slot="append">元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="卸车费" :label-width="formLabelWidth" prop="unloadFee">
                    <el-input v-model="ruleForm.unloadFee" readonly>
                      <template slot="append">元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="磅费" :label-width="formLabelWidth" prop="poundsFee">
                      <el-input v-model="ruleForm.poundsFee" readonly>
                        <template slot="append">元</template>
                      </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="其他费用" :label-width="formLabelWidth" prop="otherFee">
                      <el-input v-model="ruleForm.otherFee" readonly>
                        <template slot="append">元</template>
                      </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="待结算金额" style="color: #FFBA00" :label-width="formLabelWidth" prop="settlementAmount">
                    <el-input style="color: #FFBA00" v-model="ruleForm.settlementAmount" readonly >
                      <template slot="append">元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
            <el-card class="box-card">
              <el-row :gutter="24">
                <el-col :span="24" >
                  <el-form-item label="上传单据" :label-width="formLabelWidth" prop="images" disabled readonly>
                    <oss-upload readonly ref="upload" :echodisplaylist="settleImg" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-col :span="24">
                <el-form-item label="备注" :label-width="formLabelWidth" prop="remark" >
                  <el-input
                      readonly
                      clearable
                      type="textarea"
                      maxlength="200"
                      rows="3"
                      placeholder="请输入内容"
                      v-model="ruleForm.remark" >
                  </el-input>
                </el-form-item>
              </el-col>
            </el-card>
          </el-tab-pane>
          <el-tab-pane label="运单详情" name="order">

            <el-card class="box-card">
              <div slot="header">
                <span>车辆信息</span>
              </div>
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item label="车牌号" :label-width="formLabelWidth" prop="carownernum">
                    <el-input v-model="orderInfo.carownernum" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="司机" :label-width="formLabelWidth" prop="carname">
                    <el-input v-model="orderInfo.carname" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系电话" :label-width="formLabelWidth" prop="carphone">
                    <el-input v-model="orderInfo.carphone" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
            <el-card class="box-card">
              <div slot="header">
                <span>货物信息</span>
              </div>
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item label="货物名称" :label-width="formLabelWidth" prop="name">
                    <el-input v-model="orderInfo.name" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
              <el-col :span="8">
                  <el-form-item label="数量" :label-width="formLabelWidth" prop="weight">
                    <el-input v-model="orderInfo.weight" readonly>
                      <template slot="append">吨</template>
                    </el-input>
                  </el-form-item>
                </el-col>
              <el-col :span="8" >
                  <el-form-item label="运价" :label-width="formLabelWidth" prop="freight" >

                    <el-input v-model="orderInfo.freight" readonly>
                      <template slot="append">元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
              <el-col :span="8" style="float: right">
                <el-form-item label="总价" :label-width="formLabelWidth" prop="mineSendNum">
                  <div style="color: #FFBA00;size: 16px">{{orderInfo.weight * orderInfo.freight}}元</div>
                </el-form-item>
              </el-col>
              </el-row>
            </el-card>
            <el-card class="box-card">
              <div slot="header">
                <span>其他信息</span>
              </div>
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item label="信息费" :label-width="formLabelWidth" prop="infoFee">
                    <el-input v-model="orderInfo.infofee" readonly>
                      <template slot="append">元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="装货费" :label-width="formLabelWidth" prop="loadFee">
                    <el-input v-model="orderInfo.loadfee" readonly>
                      <template slot="append">元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="卸货费" :label-width="formLabelWidth" prop="unloadFee">
                    <el-input v-model="orderInfo.unloadfee" readonly>
                      <template slot="append">元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="磅费" :label-width="formLabelWidth" prop="poundsFee">
                    <el-input v-model="orderInfo.poundsfee" readonly>
                      <template slot="append">元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
              <el-col :span="8">
                  <el-form-item label="其他" :label-width="formLabelWidth" prop="otherFee">
                    <el-input v-model="orderInfo.otherfee" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
            <el-card class="box-card">
              <div slot="header">
                <span>货运信息</span>
              </div>
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item label="最低载重" :label-width="formLabelWidth" prop="lowWeight">
                    <el-input v-model="orderInfo.lowWeight" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="车辆类型" :label-width="formLabelWidth" prop="vehicleTypeName">
                    <el-input v-model="orderInfo.vehicleTypeName" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="车辆长度" :label-width="formLabelWidth" prop="vehicleLengthName">
                    <el-input v-model="orderInfo.vehicleLengthName" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="共需车辆" :label-width="formLabelWidth" prop="number">
                    <el-input v-model="orderInfo.number" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="接单时间" :label-width="formLabelWidth" prop="transportStartTime">
                    <el-input v-model="orderInfo.transportStartTime" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="完成时间" :label-width="formLabelWidth" prop="transportEndTime">
                    <el-input v-model="orderInfo.transportEndTime" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
               <el-col :span="12">
                  <el-form-item label="运单号" :label-width="formLabelWidth" prop="transporttakeno">
                    <el-input v-model="orderInfo.transporttakeno" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
               <el-col :span="12">
                  <el-form-item label="备注" :label-width="formLabelWidth" prop="remark">
                    <el-input v-model="orderInfo.remark" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
            <el-card class="box-card">
              <div slot="header">
                <span>收款人信息</span>
              </div>
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item label="收款人" :label-width="formLabelWidth" prop="gatheringusername">
                    <el-input v-model="orderInfo.gatheringusername" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <!--<el-col :span="8">
                  <el-form-item label="车牌号" :label-width="formLabelWidth" prop="mineSendNum">
                    <el-input v-model="orderInfo.mineSendNum" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>-->
                <el-col :span="8">
                  <el-form-item label="联系电话" :label-width="formLabelWidth" prop="gatheringuserphone">
                    <el-input v-model="orderInfo.gatheringuserphone" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
            <el-card class="box-card">
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item label="供应商" :label-width="formLabelWidth" prop="merchantName">
                    <el-input v-model="orderInfo.merchantName" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="发货人" :label-width="formLabelWidth" prop="shipUserName">
                    <el-input v-model="orderInfo.shipUserName" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系电话" :label-width="formLabelWidth" prop="shipUserPhone">
                    <el-input v-model="orderInfo.shipUserPhone" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="16">
                  <el-form-item label="发货地址" :label-width="formLabelWidth" prop="shipDetailAddress">
                    <el-input v-model="orderInfo.shipDetailAddress" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item label="采购商" :label-width="formLabelWidth" prop="receiveMerchant">
                    <el-input v-model="orderInfo.receiveMerchant" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="收货人" :label-width="formLabelWidth" prop="receiveName">
                    <el-input v-model="orderInfo.receiveName" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系电话" :label-width="formLabelWidth" prop="receivePhone">
                    <el-input v-model="orderInfo.receivePhone" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="16">
                  <el-form-item label="收货地址" :label-width="formLabelWidth" prop="receiveDetailAddress">
                    <el-input v-model="orderInfo.receiveDetailAddress" readonly>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      </vue-scroll>
      <div slot="footer" style="text-align:right" class="dialog-footer">
        <el-button type="info" size="mini" @click="cancel">取 消</el-button>
        <el-button type="primary" size="mini" v-loading.fullscreen.lock="fullscreenLoading" @click="update">结 算</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import MyImg from '@/components/img/img'
import OssUpload from '@/components/oss-upload/oss-upload.vue'

export default {
  name: 'DriverStaff',
  props: ['showFormPanel', 'item'],
  data () {
    return {
      settleImg:[],
      activeName: 'settle',
      showOperation:false,
      fullscreenLoading: false,
      customVal: {imgName: ''},
      showTreeDialog: false,
      selectOrgExpandAll: false,
      ruleForm: this.item,
      orderInfo: {},
      roleOptions: [],
      formLabelWidth: '90px',
      formLabelWidth1: '55px',
      isShow: this.showFormPanel,
      rules: {
        carLoad: [
          { required: true, message: '请输入车辆载重', trigger: 'blur' }
        ]
      }
    }
  },
  filters: {
    formatStatus: function (val) {
      if (val === 'LOCK') {
        return false
      } else if (val === 'NORMAL') {
        return true
      }
      return '-'
    }
  },
  methods: {
    selectVehicleLengths (val) {
      if (!val){
        this.ruleForm.carLength = null
        return
      }
      let obj = {}
      obj = this.vehicleLengths.find((item) => {
        return item.id === val
      })
      this.ruleForm.carLength = obj.name
    },
    selectVehicleType (val) {
      if (!val){
        this.ruleForm.typeName = null
        return
      }
      let obj = {}
      obj = this.vehicleTypes.find((item) => {
        return item.id === val
      })
      this.ruleForm.typeName = obj.name
    },
    update() {
      let self = this
/*      self.$message({
        message: '网页端暂不支持结算，请到手机APP端结算！',
        type: 'error'
      })
      return*/
      self.fullscreenLoading = true
      let par = {
        id: self.ruleForm.freightSettlementId
      }
      self.$http.post('/api/platformFreightSettle/settle', par)
        .then(function (res) {
          self.fullscreenLoading = false
          self.cancel()
          self.$emit('refreshList')
        }).catch(function (error) {
          self.fullscreenLoading = false
          console.log(error)
        })
    },
    save () {
        let self = this
        let url = 'add'
        if (self.ruleForm.carOwnerId != null) {
          url = 'update'
        }
        if (objKey){
          objKey.forEach((value, index) => {
            if (index === 0){
              self.ruleForm.vehicleLicenseFirstPic = value.objKey  ?  imgValue + value.objKey : value.url
            }
          })
        }
        if (objKey1){
          objKey1.forEach((value, index) => {
            if (index === 0){
              self.ruleForm.vehicleLicenseSecondPic = value.objKey  ?  imgValue1 + value.objKey : value.url
            }
          })
        }
        if (objKey2) {
          objKey2.forEach((value, index) => {
            if (index === 0){
              self.ruleForm.carPhoto = value.objKey  ?  imgValue2 + value.objKey : value.url
            }
          })
        }

    },
    getSettleImg(){
      let self = this
      let par = {
        id: self.item.freightSettlementId
      }
      self.$http.post("/api/platformFreightSettle/findSettleImg",par).then(function(value) {
          self.settleImg = value.data
      })
    },
    handleClick() {
      let self = this
      if (self.activeName === 'settle'){
        return
      }
      let par = {
        id: self.item.transportTakeCarriageId,
      }
      self.$http.post('/api/platformFreightSettle/findOrder', par)
          .then(function(res) {
            self.fullscreenLoading = false
            if (res.ok) {
              self.orderInfo = res.data
            }
          }).catch(function(error) {
        self.fullscreenLoading = false
        console.log(error)
      })
    },
    cancel() {
      this.$refs['ruleForm'].resetFields()
      this.isShow = false
      this.$emit('update:showFormPanel', this.isShow)
    }
  },
  mounted: function() {
    this.getSettleImg()
  },
  components: {
    OssUpload,
    MyImg
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.test {
  font-size: 13px;
  color: #606266;
  line-height: 15px;
  padding: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  font-weight: bold;
}
.el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
  margin-bottom: 15px;
}
.mark-body{
  position:fixed;
  left:0px;
  top:0px;
  background:rgba(0, 0, 0, 0.18);
  width:100%;  /*宽度设置为100%，这样才能使隐藏背景层覆盖原页面*/
  height:100%;
  filter:alpha(opacity=60);  /*设置透明度为60%*/
  opacity:0.6;  /*非IE浏览器下设置透明度为60%*/
  z-Index:999;
}
aside {
  /* background: #eef1f6; */
  /* padding: 6px 5px; */
  background: none;
  padding: 0px 24px;
  margin-bottom: 1px;
  border-radius: 2px;
  display: block;
  /* line-height: 50px; */
  /* font-size: 48px; */
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
  color: #2c3e50;
  /* -webkit-font-smoothing: antialiased; */
  -moz-osx-font-smoothing: grayscale;
}
</style>
